<template>
	<view class="content">
		<view class="order-lsit" v-for="(item,index) in arcList" :key="index">
			<view style="color: #000000;font-size: 31rpx;margin-bottom: 23rpx;">订单号：{{item.orderNo}}</view>
			<u-line color="#E7E7E7"></u-line>
			<view style="margin-top: 21rpx;display: flex;align-items: center;">患者姓名：
				<u--text color=" #000000" mode="name" :text="item.patientName" format="encrypt"></u--text>
			</view>
			<view style="margin-top: 15rpx;display: flex;align-items: center;">手机号码：
				<u--text color=" #000000" mode="phone" :text="item.patientTel" format="encrypt"></u--text>
			</view>
			<view v-if="item.userCard" style="margin-top: 15rpx;">就诊卡号：<text style="color: #000000;">
					{{item.userCard.substr(0, 1) + '****************'+item.userCard.substr(-1, 1)}}
				</text>
			</view>
			<view style="margin-top: 15rpx;">患者类型：
				<text style="color: #000000;" v-if="item.patientType == 1">门诊</text>
				<text style="color: #000000;" v-if="item.patientType == 2">住院</text>
			</view>
			<view style="margin-top: 15rpx;">充值金额：
				<text style="color: #FF1212;">¥{{item.money}}</text>
			</view>
			<view style="margin-top: 15rpx;">订单类型：
				<text style="color: #000000;" v-if="item.type == 1">门诊充值</text>
				<text style="color: #000000;" v-if="item.type == 2">预充值</text>
				<text style="color: #000000;" v-if="item.type == 3">缴费处方单</text>
				<text style="color: #000000;" v-if="item.type == 4">挂号</text>
			</view>
			<view style="margin-top: 15rpx;">支付方式：
				<text style="color: #000000;" v-if="item.payType == 0">余额</text>
				<text style="color: #000000;" v-if="item.payType == 22">微信</text>
				<text style="color: #000000;" v-if="item.payType == 23">支付宝</text>
			</view>
			<view style="margin-top: 15rpx;">支付时间：
				<text style="color: #000000;">{{parseTime(item.payTime)}}</text>

			</view>

		</view>
		<u-loadmore :status="status" />
	</view>
</template>

<script>
	import {
		ordersApi
	} from "@/api/user"
	export default {
		data() {
			return {
				pageSize: 10,
				pageNum: 1,
				isLoadMore: false,
				status: 'loading',
				arcList: [],
				selectUser: {}
			}
		},
		onLoad() {
			this.selectUser = uni.getStorageSync('selectUser')
			this.getArticle()
		},
		// 触底加载更多
		onReachBottom() {

			if (!this.isLoadMore) {
				//此处判断，上锁，防止最后一页还触发
				this.isLoadMore = true;
				this.status = 'loading'
				this.pageNum++;
				this.getArticle();
			}
		},
		methods: {
			async getArticle() {
				const res = await ordersApi({
					pageSize: this.pageSize,
					pageNum: this.pageNum,
					id: this.selectUser.id
				})
				this.arcList = [...this.arcList, ...res.rows]
				if (this.arcList.length == res.total || this.arcList.length == 0) { // 翻的页数 等于 最后一页 时显示没有更多
					this.status = 'nomore' // 没有更多了
					this.isLoadMore = true
				} else {
					this.status = 'loadmore' //继续加载
					this.isLoadMore = false //打开下拉开关
				}
			},
			parseTime(time, pattern) {
				if (arguments.length === 0 || !time) {
					return null
				}
				const format = pattern || '{y}-{m}-{d} {h}:{i}:{s}'
				let date
				if (typeof time === 'object') {
					date = time
				} else {
					if ((typeof time === 'string') && (/^[0-9]+$/.test(time))) {
						time = parseInt(time)
					} else if (typeof time === 'string') {
						time = time.replace(new RegExp(/-/gm), '/').replace('T', ' ').replace(new RegExp(/\.[\d]{3}/gm),
							'');
					}
					if ((typeof time === 'number') && (time.toString().length === 10)) {
						time = time * 1000
					}
					date = new Date(time)
				}
				const formatObj = {
					y: date.getFullYear(),
					m: date.getMonth() + 1,
					d: date.getDate(),
					h: date.getHours(),
					i: date.getMinutes(),
					s: date.getSeconds(),
					a: date.getDay()
				}
				const time_str = format.replace(/{(y|m|d|h|i|s|a)+}/g, (result, key) => {
					let value = formatObj[key]
					// Note: getDay() returns 0 on Sunday
					if (key === 'a') {
						return ['日', '一', '二', '三', '四', '五', '六'][value]
					}
					if (result.length > 0 && value < 10) {
						value = '0' + value
					}
					return value || 0
				})
				return time_str
			}
		}
	}
</script>

<style scoped>
	.content {
		padding-top: 23rpx;
		padding-bottom: calc(23px + env(safe-area-inset-bottom));
		box-sizing: border-box;
	}

	.order-lsit {
		width: 688rpx;
		background: #FFFFFF;
		border-radius: 21rpx;
		padding: 31rpx;
		box-sizing: border-box;
		margin: 0 auto;
		margin-bottom: 23rpx;
		color: #666666;
		font-size: 27rpx;
	}
</style>